package com.wcgksoft.common.factory;

import com.wcgksoft.common.charts.*;
import com.wcgksoft.common.charts.component.*;
import com.wcgksoft.common.charts.component.part.*;
import com.wcgksoft.common.factory.tool.Toolkit;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * ����ͼ�ι���
 *
 *
 * @author LIBOYI
 * @date 2015-6-17
 * @version 2.0
 *
 */
public class  ChartsFactory {
	
   /**
    * �����Ǳ���
    * @return
    * @param text �Ǳ����ı�����
    * @param fontSize �����С
    * @param value�Ǳ��̵�ֵ
    */
   public static JSONObject createGauge(String text,int fontSize,String value){
	   GaugeOptionBean option=new GaugeOptionBean();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   title.setTextStyle(textStyle);
	   option.setTitle(title);
	   //���ù�����ʾ
	   ChartsToolTipBean tooltip=new ChartsToolTipBean();
	   tooltip.setFormatter("{c}%");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean();
	   option.setToolbox(toolbox);
	   //��ֵ
	   List<ChartsGaugeSeriesBean> series=new ArrayList<ChartsGaugeSeriesBean>();
	   ChartsGaugeSeriesBean gaugeSeries=new ChartsGaugeSeriesBean();
	   GaugeDetail detail=new GaugeDetail();
	   detail.setFormatter("{value}%");
	   gaugeSeries.setName("");
	   gaugeSeries.setDetail(detail);
	   String[] data =new String[1];
	   data[0]=value;
	   gaugeSeries.setData(data);
	   gaugeSeries.setType("gauge");
	   series.add(gaugeSeries);
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   /**
    * ������״ͼ/��״�ѻ�
    * @return
    * @param text����
    * @param fontSize�����С
    * @param xAxisName x������
    * @param yAxisName y������
    * @param yAxisUnit ��λ ��"%"��"��"֮��
    * @param xData x��ֵ
    * @param dataList����
    */
   public static JSONObject createBar(String text, int fontSize, String xAxisName, String[] xData,
																			String yAxisName, String yAxisUnit, List<ChartsBarDataBean> dataList){
	   String trigger="axis";
	   String x="center";
	   String y="top";
	   boolean isShow=true;
	   String formatter="{value}"+yAxisUnit;
	   List<ChartsBarSeriesBean> series=new ArrayList<ChartsBarSeriesBean>();
	   //�õ�ͼ��
	   String[] legend =new String[dataList.size()];
	   if(!Toolkit.isEmpty(dataList)&&dataList.size()>0){
		   for (int i = 0; i < dataList.size(); i++) {
			   legend[i]=dataList.get(i).getName();
			   ChartsBarSeriesBean temp=new ChartsBarSeriesBean();
			   temp.setName(dataList.get(i).getName());
			   temp.setStack(dataList.get(i).getStack());
			   temp.setData(dataList.get(i).getData());
			   temp.setType("bar");
			   series.add(temp);
		}
		ChartsBarDataBean bar=dataList.get(0);
		if(bar.getData().length==1){
			y="bottom";
			trigger="item";
		}
	   }else{
			   series=new ArrayList<ChartsBarSeriesBean>();
			   ChartsBarSeriesBean seriesBean=new ChartsBarSeriesBean();
			   seriesBean.setData(new String[]{});
			   series.add(seriesBean);
	   }
	   BarOptionBean option =new BarOptionBean();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����ʾ
	   BarToolTipBean tooltip=new BarToolTipBean();
	   tooltip.setTrigger(trigger);
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean();
	   String[] type ={"bar","line"};
	   Feature feature=new Feature();
	   feature.setMark(new Mark(true));
	   feature.setDataView(new DataView(true));
	   feature.setDataZoom(new DataZoom(false));
	   feature.setMagicType(new MagicType(true,type));
	   feature.setRestore(new Restore(true));
	   feature.setSaveAsImage(new SaveAsImage(true));
	   toolbox.setFeature(feature);
	   toolbox.setShow(isShow);
	   option.setToolbox(toolbox);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean(x,y,legend);
	   option.setLegend(legendBean);
	   //����x��
	   XAxisBean xAxis=new XAxisBean();
	   xAxis.setName(xAxisName);
	   if(xData==null){
		   xData=new String[1];
		   xData[0]="";
	   }
	   xAxis.setData(xData);
	   option.setxAxis(xAxis);
	   //����y��
	   YAxisBean yAxis=new YAxisBean();
	   AxisLabel axisLabel=new AxisLabel(formatter);
	   yAxis.setAxisLabel(axisLabel);
	   yAxis.setName(yAxisName);
	   option.setyAxis(yAxis);
	   //����
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   /**
    * ��״�����߻��ͼ
    * @param text����
    * @param fontSize�����С
    * @param xAxisName x������
    * @param y1AxisName y1������
    * @param y2AxisName y2������
    * @param xData x��ֵ
    * @param series����
    * ��״ͼ ����name��data�������ԣ�֧�ֶѻ������ѻ�����stack
    * ����ͼ������name��data�⣬��������typeΪline
    * @param y1Unit,y2Unit ��λ ��"%"��"��"֮��
    */
   @Deprecated  
   public static JSONObject createMashupOne(String text, int fontSize, String xAxisName, String[] xData,
																						String y1AxisName, String y1Unit, String y2AxisName, String y2Unit, List<ChartsBarSeriesBean> series){
	   BarLineMashupOptionBean option=new BarLineMashupOptionBean();
	   String y1Formatter="{value}"+y1Unit;
	   String y2Formatter="{value}"+y2Unit;
	   //�õ�ͼ��
	   String[] legend =new String[series.size()];
	   if(!Toolkit.isEmpty(series)&&series.size()>0){
		   for (int i = 0; i < series.size(); i++) {
			   legend[i]=series.get(i).getName();
		}
	   }else{
		   series=new ArrayList<ChartsBarSeriesBean>();
		   ChartsBarSeriesBean seriesBean=new ChartsBarSeriesBean();
		   seriesBean.setData(new String[]{});
		   series.add(seriesBean);
	   }
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����ʾ
	   BarToolTipBean tooltip=new BarToolTipBean();
	   tooltip.setTrigger("axis");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean(true);
	   String[] type ={"bar","line"};
	   Feature feature=new Feature();
	   feature.setMark(new Mark(true));
	   feature.setDataView(new DataView(true));
	   feature.setDataZoom(new DataZoom(false));
	   feature.setMagicType(new MagicType(true,type));
	   feature.setRestore(new Restore(true));
	   feature.setSaveAsImage(new SaveAsImage(true));
	   toolbox.setFeature(feature);
	   option.setToolbox(toolbox);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean("center","top",legend);
	   option.setLegend(legendBean);
	   //����x��
	   XAxisBean xAxis=new XAxisBean();
	   xAxis.setName(xAxisName);
	   if(xData==null){
		   xData=new String[1];
		   xData[0]="";
	   }
	   xAxis.setData(xData);
	   option.setxAxis(xAxis);
	   //����y��
	   List<YAxisBean> yAxis=new ArrayList<YAxisBean>();
	   YAxisBean y1=new YAxisBean();
	   y1.setName(y1AxisName);
	   AxisLabel y1AxisLabel=new AxisLabel(y1Formatter);
	   y1.setAxisLabel(y1AxisLabel);
	   yAxis.add(y1);
	   YAxisBean y2=new YAxisBean();
	   y2.setName(y2AxisName);
	   AxisLabel y2AxisLabel=new AxisLabel(y2Formatter);
	   y2.setAxisLabel(y2AxisLabel);
	   yAxis.add(y2);
	   option.setyAxis(yAxis);
	   //����
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   /**
    * ��״�����߻��ͼ
    * @param text����
    * @param fontSize�����С
    * @param xAxisName x������
    * @param y1AxisName y1������
    * @param y2AxisName y2������
    * @param xData x��ֵ
    * @param barList ��״ͼ����
    * @param lineList ����ͼ����
    * ��״ͼ ����name��data�������ԣ�֧�ֶѻ������ѻ�����stack
    * ����ͼ������name��data�⣬��������typeΪline
    * @param y1Unit,y2Unit ��λ ��"%"��"��"֮��
    */
   public static JSONObject createMashupOne2(String text, int fontSize, String xAxisName, String[] xData,
																						 String y1AxisName, String y1Unit, String y2AxisName, String y2Unit, List<ChartsBarDataBean> barList, List<ChartsLineDataBean> lineList){
	   List<ChartsBarSeriesBean> series=new ArrayList<ChartsBarSeriesBean>();
	   if(!Toolkit.isEmpty(barList)&&barList.size()>0){
		   for (ChartsBarDataBean barDataBean : barList) {
			   ChartsBarSeriesBean barSeries=new ChartsBarSeriesBean();
			   barSeries.setData(barDataBean.getData());
			   barSeries.setName(barDataBean.getName());
			   barSeries.setStack(barDataBean.getStack());
			   series.add(barSeries);
		   }
	   }
	   if(!Toolkit.isEmpty(lineList)&&lineList.size()>0){
		   for (ChartsLineDataBean lineDataBean : lineList) {
			   ChartsBarSeriesBean barSeries=new ChartsBarSeriesBean();
			   barSeries.setData(lineDataBean.getData());
			   barSeries.setName(lineDataBean.getName());
			   barSeries.setType("line");
			   barSeries.setyAxisIndex(1);
			   series.add(barSeries);
		   }
	   }
	
	   BarLineMashupOptionBean option=new BarLineMashupOptionBean();
	   String y1Formatter="{value}"+y1Unit;
	   String y2Formatter="{value}"+y2Unit;
	   //�õ�ͼ��
	   String[] legend =new String[series.size()];
	   if(!Toolkit.isEmpty(series)&&series.size()>0){
		   for (int i = 0; i < series.size(); i++) {
			   legend[i]=series.get(i).getName();
		}
	   }else{
		   series=new ArrayList<ChartsBarSeriesBean>();
		   ChartsBarSeriesBean seriesBean=new ChartsBarSeriesBean();
		   seriesBean.setData(new String[]{});
		   series.add(seriesBean);
	   }
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����ʾ
	   BarToolTipBean tooltip=new BarToolTipBean();
	   tooltip.setTrigger("axis");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean(true);
	   String[] type ={"bar","line"};
	   Feature feature=new Feature();
	   feature.setMark(new Mark(true));
	   feature.setDataView(new DataView(true));
	   feature.setDataZoom(new DataZoom(false));
	   feature.setMagicType(new MagicType(true,type));
	   feature.setRestore(new Restore(true));
	   feature.setSaveAsImage(new SaveAsImage(true));
	   toolbox.setFeature(feature);
	   option.setToolbox(toolbox);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean("center","top",legend);
	   option.setLegend(legendBean);
	   //����x��
	   XAxisBean xAxis=new XAxisBean();
	   xAxis.setName(xAxisName);
	   if(xData==null){
		   xData=new String[1];
		   xData[0]="";
	   }
	   xAxis.setData(xData);
	   option.setxAxis(xAxis);
	   //����y��
	   List<YAxisBean> yAxis=new ArrayList<YAxisBean>();
	   YAxisBean y1=new YAxisBean();
	   y1.setName(y1AxisName);
	   AxisLabel y1AxisLabel=new AxisLabel(y1Formatter);
	   y1.setAxisLabel(y1AxisLabel);
	   yAxis.add(y1);
	   YAxisBean y2=new YAxisBean();
	   y2.setName(y2AxisName);
	   AxisLabel y2AxisLabel=new AxisLabel(y2Formatter);
	   y2.setAxisLabel(y2AxisLabel);
	   yAxis.add(y2);
	   option.setyAxis(yAxis);
	   //����
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   /**
    * ��������ͼ
    * @return
    * @param text����
    * @param fontSize�����С
    * @param xAxisName x������
    * @param yAxisName y������
    * @param xData x��ֵ
    * @param dataListֵ
    * @param unit��λ ��"%"��"��"֮��
    */
   public static JSONObject createLine(String text, int fontSize, String xAxisName, String[] xData,
																			 String yAxisName, String unit, List<ChartsLineDataBean> dataList){
	   List<ChartsLineSeriesBean> series=new ArrayList<ChartsLineSeriesBean>();
	   //�õ�ͼ��
	   String[] legend =new String[dataList.size()];
	   if(!Toolkit.isEmpty(dataList)&&dataList.size()>0){
		   for (int i = 0; i < dataList.size(); i++) {
			   legend[i]=dataList.get(i).getName();
			   ChartsLineSeriesBean temp=new ChartsLineSeriesBean();
			   temp.setName(dataList.get(i).getName());
			   temp.setData(dataList.get(i).getData());
			   temp.setType("line");
			   series.add(temp);
		}
	   }else{
		   series=new ArrayList<ChartsLineSeriesBean>();
		   ChartsLineSeriesBean seriesBean=new ChartsLineSeriesBean();
		   seriesBean.setData(new String[]{});
		   series.add(seriesBean);
	   }
	 
	   LineOptionBean option =new LineOptionBean();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����ʾ
	   BarToolTipBean tooltip=new BarToolTipBean("axis");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean(true);
	   String[] type ={"line","bar"};
	   Feature feature=new Feature();
	   feature.setMark(new Mark(true));
	   feature.setDataView(new DataView(true));
	   feature.setDataZoom(new DataZoom(false));
	   feature.setMagicType(new MagicType(true,type));
	   feature.setRestore(new Restore(true));
	   feature.setSaveAsImage(new SaveAsImage(true));
	   toolbox.setFeature(feature);
	   option.setToolbox(toolbox);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean("center","top",legend);
	   option.setLegend(legendBean);
	   //����x��
	   XAxisBean xAxis=new XAxisBean();
	   xAxis.setName(xAxisName);
	   if(xData==null){
		   xData=new String[1];
		   xData[0]="";
	   }
	   xAxis.setData(xData);
	   option.setxAxis(xAxis);
	   //����y��
	   YAxisBean yAxis=new YAxisBean();
	   yAxis.setName(yAxisName);
	   String formatter="{value} "+unit;
	   AxisLabel axisLabel=new AxisLabel(formatter);
	   yAxis.setAxisLabel(axisLabel);
	   option.setyAxis(yAxis);
	   //����
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   
   /**
    * ������ͼ
    * @return
    * @param text ����
    * @param fontSize�����С
    * @param x ͼ��ˮƽ����λ�ã�Ĭ��Ϊȫͼ���У���ѡΪ��'center' | 'left' | 'right'
    * @param y ͼ����ֱ����λ�ã�Ĭ��Ϊȫͼ���ˣ���ѡΪ��'top' | 'bottom' | 'center'
    * @param radius�뾶 ��ʽ50%
    * @param data��ͼ����
    * 
    */
   public static JSONObject createPie(String text,int fontSize,String x,String y,
		String radius,List<PieDataBean> data){
	   String[] radiusArray =new String[2];
	   radiusArray[0]="0%";
	   radiusArray[1]=radius;
	   JSONObject  jsonObject = createPieAndRingJson(text,fontSize,x,y,radiusArray,data);
	   return jsonObject;
   }
   /**
    * ��������ͼ
    * @return
    * @param text ����
    * @param fontSize�����С
    * @param x ͼ��ˮƽ����λ�ã�Ĭ��Ϊȫͼ���У���ѡΪ��'center' | 'left' | 'right'
    * @param y ͼ����ֱ����λ�ã�Ĭ��Ϊȫͼ���ˣ���ѡΪ��'top' | 'bottom' | 'center'
    * @param innerRadius�ڰ뾶����ʽ20%
    * @param outerRadius��뾶����ʽ30%
    * @param data����ͼ����
    */
   public static JSONObject createRing(String text,int fontSize,String x,String y,
		String innerRadius,String outerRadius,List<PieDataBean> data){
	   String[] radiusArray =new String[2];
	   radiusArray[0]=innerRadius;
	   radiusArray[1]=outerRadius;
	   JSONObject  jsonObject = createPieAndRingJson(text,fontSize,x,y,radiusArray,data);
	   return jsonObject;
   }
   /**
    * ��ͼ�ͻ���ͼ����json
    * @param text ����
    * @param fontSize�����С
    * @param x ͼ��ˮƽ����λ�ã�Ĭ��Ϊȫͼ���У���ѡΪ��'center' | 'left' | 'right'
    * @param y ͼ����ֱ����λ�ã�Ĭ��Ϊȫͼ���ˣ���ѡΪ��'top' | 'bottom' | 'center'
    * @param radiusArray[]�뾶���飬[�ڰ뾶����뾶] ��ʽ{"50%", "70%"}
    */
   private static JSONObject createPieAndRingJson(String text, int fontSize, String x, String y,
																									String[] radiusArray, List<PieDataBean> data){
	   PieOptionBean option =new PieOptionBean();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����ʾ
	   ChartsToolTipBean tooltip=new ChartsToolTipBean();
	   tooltip.setFormatter("{a} <br/>{b} : {c} ({d}%)");
	   tooltip.setTrigger("item");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean(true);
	   String[] type ={"pie", "funnel"};
	   Feature feature=new Feature(new Mark(false),new DataView(true),
				new MagicType(true,type),new  Restore(true),new  SaveAsImage(true));
	   toolbox.setFeature(feature);
	   option.setToolbox(toolbox);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean(x,y);
	   String[] legendData=new String[data.size()];
	   if(!Toolkit.isEmpty(data)&&data.size()>0){
		   for (int i = 0; i < data.size(); i++) {
			   legendData[i]=data.get(i).getName();
		}
	   }
	   legendBean.setData(legendData);
	   option.setLegend(legendBean);
	   List<ChartsPieSeriesBean> series=new ArrayList<ChartsPieSeriesBean>();
	   ChartsPieSeriesBean ringSeries=new ChartsPieSeriesBean();
	   
	   //����
	   ringSeries.setName(text);
	   ringSeries.setType("pie");
	   ringSeries.setRadius(radiusArray);
	   ringSeries.setData(data);
	   series.add(ringSeries);
	   option.setSeries(series);
	   return JSONObject.fromObject(option);
   }

   /**
    * ��׼���ͼ/�ѻ����ͼ
    * @param text ����
    * @param fontSize
    * @param xAxisName x������
    * @param yAxisName y������
    * @param xData x��ֵ
    * @param unit��λ ��"%"��"��"֮��
    * @param dataList����
    * @return
    */
   public static JSONObject createAreaStack(String text, int fontSize, String xAxisName, String[] xData,
																						String yAxisName, String unit, List<AreaStackChartsDataBean> dataList){
	   AreaStackOptionBean option=new AreaStackOptionBean();
	   List<ChartsAreaStackSeriesBean> series=new ArrayList<ChartsAreaStackSeriesBean>();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean();
	   String[] legendData=new String[dataList.size()];
	   if(!Toolkit.isEmpty(dataList)&&dataList.size()>0){
		   for (int i = 0; i < dataList.size(); i++) {
			   legendData[i]=dataList.get(i).getName();
			   ChartsAreaStackSeriesBean temp=new ChartsAreaStackSeriesBean();
			   temp.setData(dataList.get(i).getData());
			   temp.setName(dataList.get(i).getName());
			   temp.setStack(dataList.get(i).getStack());
			   temp.setType("line");
			   series.add(temp);
			   
		}
	   }else{
		   ChartsAreaStackSeriesBean seriesBean=new ChartsAreaStackSeriesBean();
		   seriesBean.setData(new String[]{});
		   series.add(seriesBean);
	   }
	   legendBean.setData(legendData);
	   option.setLegend(legendBean);
	   //����x��
	   List<XAxisBean> xAxis=new ArrayList<XAxisBean>();
	   XAxisBean x1=new XAxisBean(true);
	   x1.setName(xAxisName);
	   if(xData==null){
		   xData=new String[1];
		   xData[0]="";
	   }
	   x1.setData(xData);
	   xAxis.add(x1);
	   option.setxAxis(xAxis);
	   //����y��
	   List<YAxisBean> yAxis=new ArrayList<YAxisBean>();
	   YAxisBean y1=new YAxisBean();
	   y1.setName(yAxisName);
	   String formatter="{value} "+unit;
	   AxisLabel axisLabel=new AxisLabel(formatter);
	   y1.setAxisLabel(axisLabel);
	   yAxis.add(y1);
	   option.setyAxis(yAxis);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean();
	   Feature feature=new Feature(new Mark(false),new DataZoom(false),new DataView(true),
				new MagicType(true,new String[]{"line","bar","stack","tiled"}),new  Restore(true),new SaveAsImage(true));
	   toolbox.setFeature(feature);
	   option.setToolbox(toolbox);
	   //����
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   
   /**
    * �¶ȼ�ʽͼ��
    * @param text ����
    * @param fontSize
    * @param xAxisName x������
    * @param yAxisName y������
    * @param xData x��ֵ
    * @param unit��λ ��"%"��"��"֮��
    * @param thermometerList����
    * @return
    */
   public static JSONObject createTermometer(String text, int fontSize, String xAxisName, String[] xData,
																						 String yAxisName, String unit, List<ThermometerBean> thermometerList){
	   ThermometerOptionBean option=new ThermometerOptionBean();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean();
	   Feature feature=new Feature(new Mark(true),new DataZoom(false),new DataView(true),
				new MagicType(false),new Restore(true),new SaveAsImage(true));
	   toolbox.setFeature(feature);
	   option.setToolbox(toolbox);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean();
	   String[] legendData=new String[thermometerList.size()];
	   if(!Toolkit.isEmpty(thermometerList)&&thermometerList.size()>0){
		   for (int i = 0; i < thermometerList.size(); i++) {
			   legendData[i]=thermometerList.get(i).getName();
		}
	   }
	   legendBean.setSelectedMode(true);
	   legendBean.setData(legendData);
	   option.setLegend(legendBean);
	   //����x��
	   List<XAxisBean> xAxis=new ArrayList<XAxisBean>();
	   XAxisBean x1=new XAxisBean(true);
	   x1.setName(xAxisName);
	   if(xData==null){
		   xData=new String[1];
		   xData[0]="";
	   }
	   x1.setData(xData);
	   xAxis.add(x1);
	   option.setxAxis(xAxis);
	   //����y��
	   List<YAxisBean> yAxis=new ArrayList<YAxisBean>();
	   YAxisBean y1=new YAxisBean();
	   y1.setName(yAxisName);
	   String formatter="{value} "+unit;
	   AxisLabel axisLabel=new AxisLabel(formatter);
	   y1.setAxisLabel(axisLabel);
	   yAxis.add(y1);
	   option.setyAxis(yAxis);
	   List<ThermometerSeriesBean> series=new ArrayList<ThermometerSeriesBean>();
	   if(!Toolkit.isEmpty(thermometerList)&&thermometerList.size()>1){
		   ThermometerBean thermometer= thermometerList.get(0);
		   ThermometerSeriesBean temp=new ThermometerSeriesBean();
		   temp.setName(thermometer.getName());
		   temp.setData(thermometer.getData());
		   temp.setStack("stack");
		   ThermometerItemStyle itemStyle=new ThermometerItemStyle(new ThermometerBaseItemStyle("tomato",
				   new Label("insideTop",new TextStyle("#fff"))));
		   temp.setItemStyle(itemStyle);
		   temp.setType("bar");
		   series.add(temp);
		   
		   ThermometerBean thermometerBean= thermometerList.get(1);
		   ThermometerSeriesBean tempBean=new ThermometerSeriesBean();
		   tempBean.setName(thermometerBean.getName());
		   tempBean.setData(thermometerBean.getData());
		   tempBean.setStack("stack");
		   tempBean.setType("bar");
		   ThermometerItemStyle itemStyleBean=new ThermometerItemStyle(new ThermometerBaseItemStyle("#fff",
				   new Label("top",new TextStyle("tomato"))));
		   tempBean.setItemStyle(itemStyleBean);
		   series.add(tempBean);
	   }
	   //����
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   /**
    * ����©��ͼ
    * @return
    * @param text ����
    * @param fontSize �����С
    * @param dataList©��ͼ��ֵ
    */
   public static JSONObject createFunnel(String text,int fontSize,List<ChartsDataBean> dataList){
	   FunnelOptionBean option=new FunnelOptionBean();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   title.setTextStyle(textStyle);
	   option.setTitle(title);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean();
	   String[] legendData=new String[dataList.size()];
	   if(!Toolkit.isEmpty(dataList)&&dataList.size()>0){
		   for (int i = 0; i < dataList.size(); i++) {
			   legendData[i]=dataList.get(i).getName();
		}
	   }
	 
	   legendBean.setX("center");
	   legendBean.setY("bottom"); 
	   legendBean.setSelectedMode(true);
	   legendBean.setData(legendData);
	   option.setLegend(legendBean);
	   //���ù�����ʾ
	   ChartsToolTipBean tooltip=new ChartsToolTipBean("item","{a} <br/>{b} : {c}");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean(true,new Feature(new Mark(false),
			   new DataView(true),new MagicType(false),new Restore(true),new SaveAsImage(true)));
	   toolbox.setShow(true);
	   option.setToolbox(toolbox);
	   //����
	   List<ChartsFunnelSeriesBean> series=new ArrayList<ChartsFunnelSeriesBean>();
	   ChartsFunnelSeriesBean funnelSeries=new ChartsFunnelSeriesBean();
	   funnelSeries.setName(text);
	   funnelSeries.setData(dataList);
	   funnelSeries.setType("funnel");
	   series.add(funnelSeries);
	   option.setSeries(series);
	   JSONObject  jsonObject =JSONObject.fromObject(option);
	   return jsonObject;
   }
   /**
    * ����õ��ͼ
    * @return
    * @param text����
    * @param fontSize�����С
    * 
    */
   public static JSONObject createRose(String text,int fontSize,
		List<PieDataBean> data){
	   RoseDiagramOptionBean option =new RoseDiagramOptionBean();
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����ʾ
	   ChartsToolTipBean tooltip=new ChartsToolTipBean();
	   tooltip.setFormatter("{a} <br/>{b} : {c} ({d}%)");
	   tooltip.setTrigger("item");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean(true);
	   String[] type ={"pie", "funnel"};
	   Feature feature=new Feature(new Mark(false),new DataView(true),
				new MagicType(true,type),new  Restore(true),new  SaveAsImage(true));
	   toolbox.setFeature(feature);
	   option.setToolbox(toolbox);
	   //����ͼ��
	   LegendBean legendBean=new LegendBean("center","bottom");
	   String[] legendData=new String[data.size()];
	   if(!Toolkit.isEmpty(data)&&data.size()>0){
		   for (int i = 0; i < data.size(); i++) {
			   legendData[i]=data.get(i).getName();
		}
	   }
	   legendBean.setData(legendData);
	   option.setLegend(legendBean);
	   List<ChartsRoseSeriesBean> series=new ArrayList<ChartsRoseSeriesBean>();
	   ChartsRoseSeriesBean roseSeries=new ChartsRoseSeriesBean();
	   //����
	   String[] radius ={"20","110"};
	   roseSeries.setName(text);
	   roseSeries.setType("pie");
	   roseSeries.setRadius(radius);
	   roseSeries.setRoseType("area");
	   roseSeries.setData(data);
	   series.add(roseSeries);
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
   /**
    * �����й���ͼ
    * @return
    * @param text��״ͼ����
    * @param fontSize�����С
    * 
    */
   public static JSONObject createChinaMap(String text,int fontSize,List<MapDataBean> data){
	   ChinaMapOptionBean option =new ChinaMapOptionBean();
	   List<ChartsMapSeriesBean> series=new ArrayList<ChartsMapSeriesBean>();
	   String[] legendData=new String[data.size()];
	   List<ChartsDataBean> valueList=new ArrayList<ChartsDataBean>(); 
	   int dataRangeMax=0;
	   if(!Toolkit.isEmpty(data)&&data.size()>0){
		   for (int i = 0; i < data.size(); i++) {
			   legendData[i]=data.get(i).getName();
			   ChartsMapSeriesBean seriesBean=new ChartsMapSeriesBean();
			   seriesBean.setMapType("china");
			   seriesBean.setType("map");
			   seriesBean.setName(data.get(i).getName());
			   seriesBean.setData(data.get(i).getData());
			   valueList.addAll(data.get(i).getData());
			   MapItemStyle itemStyle=new MapItemStyle();
			   MapItemStyleNormal normal=new MapItemStyleNormal();
			   MapItemStyleEmphasis emphasis=new MapItemStyleEmphasis();
			   itemStyle.setNormal(normal);
			   itemStyle.setEmphasis(emphasis);
			   seriesBean.setItemStyle(itemStyle);
			   series.add(seriesBean);
		   }
		   int[] valueArray =new int[valueList.size()];
		   for (int i = 0; i < valueList.size(); i++) {
			   valueArray[i]=Integer.parseInt(valueList.get(i).getValue());
		   }
		   Arrays.sort(valueArray);
		   dataRangeMax=valueArray[valueArray.length-1];
	   }
	   //���ñ���
	   ChartsTitleBean title=new ChartsTitleBean();
	   title.setText(text);
	   title.setX("center");
	   TextStyle textStyle=new TextStyle();
	   textStyle.setFontSize(fontSize);
	   option.setTitle(title);
	   //���ù�����ʾ
	   ChartsChinaMapToolTipBean tooltip=new ChartsChinaMapToolTipBean();
	   tooltip.setTrigger("item");
	   option.setTooltip(tooltip);
	   //���ù�����
	   ChartsToolBoxBean toolbox=new ChartsToolBoxBean(true);
	   String[] type ={""};
	   Feature feature=new Feature(new Mark(true),new DataView(true),
				new MagicType(false,type),new  Restore(true),new  SaveAsImage(true));
	   toolbox.setFeature(feature);
	   toolbox.setX("right");
	   toolbox.setY("center");
	   toolbox.setOrient("vertical");
	   option.setToolbox(toolbox);
	   //ֵ������
	   DataRange dataRange=new DataRange();
	   dataRange.setX("left");
	   dataRange.setY("bottom");
	   dataRange.setCalculable(true);
	   dataRange.setMin(0);
	   dataRange.setMax(dataRangeMax);
	   option.setDataRange(dataRange);
	   //ָ����������ɿص�ͼ����
	   RoamController roamController=new RoamController();
	   roamController.setShow(true);
	   roamController.setX("right");
	   MapTypeControl mapTypeControl=new MapTypeControl();
	   mapTypeControl.setChina(true);
	   roamController.setMapTypeControl(mapTypeControl);
	   option.setRoamController(roamController);
	   //����ͼ��
	   LegendBean legend=new LegendBean();
	   legend.setOrient("vertical");
	   legend.setX("left");
	   legend.setData(legendData);
	   option.setLegend(legend);
	   //��������
	   option.setSeries(series);
	   JSONObject  jsonObject = JSONObject.fromObject(option);
	   return jsonObject;
   }
}
